﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using l1cs.server.model.Instance;
using l1cs.server.model;
using l1cs.server.serverpackets;

namespace l1cs.server.clientpackets
{
    public class C_Pledge : ClientBasePacket
    {
        private const String _C_PLEDGE = "[C] C_Pledge";
        private static Logger _log = Logger.getLogger( typeof( C_Pledge ).FullName );

        public C_Pledge( byte[] abyte0, ClientThread clientthread )
            : base( abyte0 )
        {

            L1PcInstance pc = clientthread.getActiveChar();

            if ( pc.getClanid() > 0 )
            {
                L1Clan clan = L1World.getInstance().getClan( pc.getClanname() );
                if ( pc.isCrown() && pc.getId() == clan.getLeaderId() )
                {
                    pc.sendPackets( new S_Pledge( "pledgeM", pc.getId(),
                            clan.getClanName(), clan.getOnlineMembersFPWithRank(),
                            clan.getAllMembersFPWithRank() ) );
                }
                else
                {
                    pc.sendPackets( new S_Pledge( "pledge", pc.getId(),
                            clan.getClanName(), clan.getOnlineMembersFP() ) );
                }
            }
            else
            {
                pc.sendPackets( new S_ServerMessage( 1064 ) ); // 血盟に属していません。
                // pc.sendPackets(new S_Pledge("pledge", pc.getId()));
            }
        }

        override
        public String getType()
        {
            return _C_PLEDGE;
        }
    }
}